package com.rbcs.base.currency.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.rbcs.base.model.ExchangeRate;
import com.systop.core.service.BaseGenericsManager;

/**
 * 币种汇率管理Manager
 * @author ShangHua
 */
@Service
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ExchangeRateManager extends BaseGenericsManager<ExchangeRate> {

	/**
	 * 根据币种以及年度信息来获取该币种该年度的汇率信息
	 * @param currencyId
	 * @param year
	 * @return
	 */
	public ExchangeRate getExchangeRate(Integer currencyId, String year) {
		ExchangeRate exchangeRate = (ExchangeRate) getDao().findObject(
				"from ExchangeRate er where er.currency.id = ? and er.year = ? ",
				new Object[] {currencyId, year });
		return exchangeRate;
	}
	
	/**
	 * 将某个币种全年各个月份的汇率存放到Map中
	 * @param exchangeRate
	 * @return
	 */
	public Map getRatesMap(ExchangeRate exchangeRate) {
		Map rateMap = new HashMap();
		rateMap.put("1", exchangeRate.getJanuaryRate());
		rateMap.put("2", exchangeRate.getFebruaryRate());
		rateMap.put("3", exchangeRate.getMarchRate());
		rateMap.put("4", exchangeRate.getAprilRate());
		rateMap.put("5", exchangeRate.getMayRate());
		rateMap.put("6", exchangeRate.getJuneRate());
		rateMap.put("7", exchangeRate.getJulyRate());
		rateMap.put("8", exchangeRate.getAugustRate());
		rateMap.put("9", exchangeRate.getSeptemberRate());
		rateMap.put("10", exchangeRate.getOctoberRate());
		rateMap.put("11", exchangeRate.getNovemberRate());
		rateMap.put("12", exchangeRate.getDecemberRate());		
		return rateMap;
	}

}
